package cn.youqu.happy.module.youqu.convert.userArrange;

import cn.hutool.core.collection.CollUtil;
import cn.youqu.happy.framework.common.pojo.PageResult;
import cn.youqu.happy.module.youqu.controller.admin.userArrange.vo.*;
import cn.youqu.happy.module.youqu.controller.app.userArrange.vo.AppUserArrangeCreateReqVO;
import cn.youqu.happy.module.youqu.controller.app.userArrange.vo.AppUserArrangePageReqVO;
import cn.youqu.happy.module.youqu.controller.app.userArrange.vo.AppUserArrangeRespVO;
import cn.youqu.happy.module.youqu.controller.app.userArrange.vo.AppUserArrangeUpdateReqVO;
import cn.youqu.happy.module.youqu.controller.app.userTell.vo.AppUserTellPageReqVO;
import cn.youqu.happy.module.youqu.controller.app.userTell.vo.AppUserTellRespVO;
import cn.youqu.happy.module.youqu.dal.dataobject.userActivity.UserActivityDO;
import cn.youqu.happy.module.youqu.dal.dataobject.userArrange.UserArrangeDO;
import org.mapstruct.Mapper;
import org.mapstruct.Mapping;
import org.mapstruct.Mappings;
import org.mapstruct.factory.Mappers;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.stream.Collectors;

/**
 * 用户计划 Convert
 *
 * @author 王其岩 20112001045
 */
@Mapper(componentModel = "spring")
public interface UserArrangeConvert {

    UserArrangeConvert INSTANCE = Mappers.getMapper(UserArrangeConvert.class);

    @Mappings({
            @Mapping(target = "partners", source = "bean.partnerList")
    })
    UserArrangeDO convert(UserArrangeCreateReqVO bean);

    @Mappings({
            @Mapping(target = "partners", source = "bean.partnerList")
    })
    UserArrangeDO convert(UserArrangeUpdateReqVO bean);

    @Mappings({
            @Mapping(target = "partnerList", source = "bean.partners")
    })
    UserArrangeRespVO convert(UserArrangeDO bean);

    @Mappings({
            @Mapping(target = "partnerList", source = "bean.partners")
    })
    AppUserArrangeRespVO convert0(UserArrangeDO bean);


    UserArrangeUpdateReqVO convert1(UserArrangeDO bean);


    List<UserArrangeRespVO> convertList(List<UserArrangeDO> list);

    List<AppUserArrangeRespVO> convertList0(List<UserArrangeDO> list);

    PageResult<UserArrangeRespVO> convertPage(PageResult<UserArrangeDO> page);

    PageResult<AppUserArrangeRespVO> convertPage0(PageResult<UserArrangeDO> page);

    List<UserArrangeExcelVO> convertList02(List<UserArrangeDO> list);

    UserArrangeDO convert(AppUserArrangeUpdateReqVO updateReqVO);

    UserArrangePageReqVO convert(AppUserArrangePageReqVO pageVO);

    UserArrangeCreateReqVO convert(AppUserArrangeCreateReqVO createReqVO);

    @Mappings({
            @Mapping(target = "startDate", source = "appointTime"),
            @Mapping(target = "activityId", source = "id"),
            @Mapping(target = "partnerList", source = "partners")
    })
    UserArrangeCreateReqVO convert(UserActivityDO activityDO);


    AppUserTellRespVO convert(AppUserTellPageReqVO pageVO);

    default String list2str(List<String> src) {
        if (CollUtil.isEmpty(src)) {
            return "";
        }
        return String.join(",", src);
    }

    default List<String> str2List(String str) {
        if (str == null || str.isEmpty()) return new ArrayList<>();
        String[] split = str.split(",");
        return Arrays.asList(split);
    }

    default List<Long> str2List2(String src) {
        if (src == null || src.isEmpty()) return new ArrayList<Long>();
        String[] split = src.split(",");
        return Arrays.asList(split).stream().map(item -> Long.valueOf(item)).collect(Collectors.toList());
    }

    default String list2Str2(List<Long> src) {
        if (CollUtil.isEmpty(src)) {
            return "";
        }
        List<String> collect = src.stream().map(item -> String.valueOf(item)).collect(Collectors.toList());
        return String.join(",", collect);
    }

}
